import Vue from 'vue'

const state = {
  projectDetail: {}
}

const getters = {
  getProjectDetail: state => {
    return state.projectDetail
  }
}

const mutations = {
  muProjectDetail (state, payload) {
    state.projectDetail = payload.detail
  }
}

const actions = {
  actProjectDetail ({ commit }, payload) {
    return new Promise((resolve, reject) => {
      const data = {}
      if (payload) {
        data['query.project_id'] = payload.pjId
      }
      Vue.prototype.$axios({
        method: 'post',
        url: `${Vue.prototype.$site.projectServer}/front/person/getProjectDetail.htm`,
        data: Vue.prototype.$qs.stringify(data),
        closeSaveRequest: true
      }).then(res => {
        if (res.data.errorMsg) {
          resolve(res)
          return
        }
        // 成功回调
        commit({
          type: 'muProjectDetail',
          detail: res.data.detail
        })
        resolve(res)
      }, err => {
        reject(err)
      })
    })
  }
}

export default {
  state,
  getters,
  mutations,
  actions
}
